
define(["./dom", "./ajax", "jquery", "bootstrap"], function(dom, ajax, $) {
  var doLookup, exports, init;
  doLookup = function($field, url, query, process) {
    $field.addClass("ajax-wait");
    return ajax(url, {
      parameters: {
        "t:input": query
      },
      success: function(response) {
        $field.removeClass("ajax-wait");
        return process(response.json.matches);
      }
    });
  };
  init = function(spec) {
    var $field;
    $field = $(document.getElementById(spec.id));
    return $field.typeahead({
      minLength: spec.minChars,
      source: function(query, process) {
        return doLookup($field, spec.url, query, process);
      }
    });
  };
  return exports = init;
});
